/*
 * @Author: ellery
 * @Date: 2022-08-26 22:43:42
 * @LastEditTime: 2022-09-05 16:46:18
 * @LastEditors: ellery
 * @Description: 动态路由配置
 * @FilePath: \vue2-eslint-model\src\router\index.js
 * Copyright (c) 2022 by ellery, All Rights Reserved.
 * 愿天堂没代码
 */
import Vue from "vue";
import Router from "vue-router";
import routes from "./routes";
Vue.use(Router);

routes.push({
  path: "*",
  redirect: "/Login"
});
const router = new Router({
  routes: routes
});
// 全局前置守卫：初始化时执行、每次路由切换前执行
router.beforeEach((to, from, next) => {
  // console.log("beforeEach", to);
  if (to.meta.isKey) {
    next();
  } else {
    router.push({ name: "404" });
  }
});

// 全局后置守卫：初始化时执行、每次路由切换后执行
router.afterEach((to, from) => {
  // console.log("afterEach", to, from);
});
export default router;
